package org.example.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.example.pojo.Department;
import org.example.pojo.DepartmentIdAndName;
import org.example.service.DepartmentService;
import org.example.util.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@Api(tags = "部门id和name查询")
@RequestMapping("/departmentIdAndName")
public class DepartmentIdAndNameController {

    @Autowired
    DepartmentService departmentService;

    @GetMapping("/showDepartmentIdAndName")
    @ApiOperation("部门id和name")
    @ResponseBody
    public ResponseData showDepartmentIdAndName(){


        List<DepartmentIdAndName> departmentIdAndNames = departmentService.showDepartmentIdAndName();

        PageInfo<DepartmentIdAndName> departmentPageInfo = new PageInfo<>(departmentIdAndNames);

        //以json传输
        ResponseData jsonData = ResponseData.getJsonData(departmentIdAndNames,(int)departmentPageInfo.getTotal());

        return jsonData;
    }


}
